package com.qire.manhua.controller;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.qire.common.basic.ObjectUtil;
import com.qire.manhua.BR;
import com.qire.manhua.databinding.FragmentRecommendBoysBinding;
import com.qire.manhua.fragment.RecommendBoysFragment;
import com.qire.manhua.model.viewModel.impl.RecommendBoysViewModel;
import com.qire.manhua.model.viewModel.impl.RecommendBoysViewModel.BoysSlideZoneViewModel.BoysBannerItemViewModel;

public class RecommendBoysController extends RecommendModuleController<RecommendBoysFragment> {

    private RecommendBoysViewModel viewModel;

    public RecommendBoysController(@NonNull RecommendBoysFragment lifecycleOwner) {
        super(lifecycleOwner);
    }

    @Override
    protected void bindView() {
        FragmentRecommendBoysBinding viewDataBinder = owner.viewDataBinder();
        if(viewDataBinder != null) {
            viewDataBinder.setRecommendBoysController(this);
        }
    }

    @Override
    public void bindVariable(ViewDataBinding viewBind) {
        super.bindVariable(viewBind);
        viewBind.setVariable(BR.recommendBoysController, this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(RecommendBoysViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void bannerOnPageSelected(int position) {
        if(ObjectUtil.nonNull(viewModel)) {
            viewModel.changeBannerBackground(position);
        }
    }

    /**
     * 点击banner广告
     * @param view
     */
    public void onBannerItemClick(View view) {
        BoysBannerItemViewModel bannerItemViewModel = (BoysBannerItemViewModel) view.getTag();
        bannerItemViewModel.doAction();
    }

    public void errorReloadBtnOnClick(View view) {
//        presenter().loadPageData();
    }

}
